# vim:ts=4:sw=4:noet:
import unittest
from c.compiler.lexer import Lexer
from c.base.support import Status

class LexerTests(unittest.TestCase):
	def setUp(self):
		self.stat = Status({"exceptions":True})

	def checkLex(self, code, expect):
		l = Lexer(self.stat, code)
		l.nextLex()
		for eline in expect:
			eln = eline[0]
			evals = eline[1:]
			for ev in evals:
				self.failUnless(l.token)
				t = l.token
				self.assertEqual(l.lineNum, eln)
				self.assertEqual(t.value, ev)
				l.nextLex()

	def testExampleA(self):
		self.checkLex("""
|n|

"hello world"
4 > n ifTrue: [
	'hello' printNl
].
""",(
				(2, "|", "n", "|"), 
				(5, "4", ">", "n", "ifTrue:", "["),
				(6, "hello", "printNl"),
				(7, "]", ".")))
	
	def testExampleB(self):
		self.checkLex("""
"moocow

cheese
"
4 > n * 3 'mooo' "wookly" x
#( )
""",(
				(6, "4", ">", "n", "*", "3", "mooo", "x"),
				(7, "#(", ")")))

	def testSingleCharString(self):
		self.checkLex("'[' print.",
				((1, "[", "print"),))

